package quoridor;


public class QuoridorMove implements Move
{
   private Coordinate target;
   
   /**
    * Identifies the type of move.
    * 0 - move piece
    * 1 - place vertical fence
    * 2 - place horozontal fence
    *-1 - invalid
    */
   private int type;
   
   private PlayerColour playerColour;
   
   public QuoridorMove(Coordinate newTarget, int newType, PlayerColour newPlayerColour)
   {
      target = newTarget;
      type = newType;
      playerColour = newPlayerColour;
   }
   
   public QuoridorMove(PlayerColour newPlayerColour, String moveString) {
	   playerColour = newPlayerColour;

	   if (moveString.charAt(2) == ' ') {
		   type = 0;
	   } else {
		   if (moveString.charAt(2) == 'v') {
			   type = 1;
		   } else if (moveString.charAt(2) == 'h') {
			   type = 2;
		   } else {
			   type = -1;
		   }
	   }
	   
	   char columnCharacter = moveString.charAt(0);
	   int row = Character.getNumericValue(moveString.charAt(1));
	   target = new QuoridorCoordinate(row, columnCharacter);
   }
   
   public Coordinate getCoordinate()
   {
      return target;
   }

   public int getType()
   {
      switch (type) {
         case (0): return 0;
         case (-1): return -1;
         case (1): return 1;
         case (2): return 2;
         default: return 1;
      }
   }
   
   public PlayerColour getPlayer()
   {
      return playerColour;
   }
   
   public boolean isVertical()
   {
      return type > 0;
   }

}
